package vn.com.vega.music.player;

import vn.com.vega.chacha.R;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;

public class ChaChaProgressDialog extends Dialog {
	private Context mContext;
	private Handler mHandler;
	private TextView mMessage;
	private ProgressBar mProgressBar;
	private static int TIME_AUTO_HIDE = 10000; // after this time if dialog still show, it will auto hide.
	
	public ChaChaProgressDialog(Context context, int theme) {
		super(context, theme);
		// TODO Auto-generated constructor stub
		init(context);
	}

	public ChaChaProgressDialog(Context context) {
		super(context, R.style.Theme_CustomDialog);
		// TODO Auto-generated constructor stub
		init(context);
	}
	
	private void init(Context ctx) {
		setContentView(R.layout.layout_progress_dialog);
		mContext = ctx;
		mHandler = new Handler();
		mMessage = (TextView) findViewById(R.id.tv_progress_dialog);
		mProgressBar = (ProgressBar) findViewById(R.id.progressBar_progress_dialog);
	}
	
	Runnable hide = new Runnable() {
		
		@Override
		public void run() {
			// TODO Auto-generated method stub
			if (isShowing()) {
				try {
					dismiss();
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
				
			}
		}
	};

	@Override
	public void show() {
		// TODO Auto-generated method stub
		super.show();
		mHandler.postDelayed(hide, TIME_AUTO_HIDE);
	}
	
	public void setTimeAutoHide (int time) {
		TIME_AUTO_HIDE = time;
	}

	@Override
	public void dismiss() {
		// TODO Auto-generated method stub
		super.dismiss();
		mHandler.removeCallbacks(hide);
	}

	public void setMessage(CharSequence message) {
		// TODO Auto-generated method stub
		mMessage.setText(message);
	}

}
